package com.qianbao.qianbaobusiness.ui.deposit;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.androidbase.widget.recycleadpter.BaseRecycleViewAdapter;
import com.baseandroid.config.Api;
import com.baseandroid.config.Global;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.UnPayShopListBean;
import com.qianbao.qianbaobusiness.ui.webview.SimpleWebViewActivity;

public class MyDepositAdapter extends BaseRecycleViewAdapter<UnPayShopListBean.MerchantWaitPayInfoBean> {
    private Context context;

    public MyDepositAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    protected void onBindBaseViewHolder(RecyclerView.ViewHolder holder, final UnPayShopListBean.MerchantWaitPayInfoBean item) {
        final ShopViewHolder shopViewHolder = (ShopViewHolder) holder;
        shopViewHolder.shopName.setText(item.getMerchantName());
        shopViewHolder.shopAddr.setText(item.getProvinceName() + "-" + item.getCityName() + "-"
                                                + item.getDistrictName());
        if (item.getWaitPayCount().equals("0")) {
            shopViewHolder.depositNum.setVisibility(View.GONE);
        } else {
            shopViewHolder.depositNum.setVisibility(View.VISIBLE);
            shopViewHolder.depositNum.setText(item.getWaitPayCount());
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //                if (!item.getWaitPayCount().equals("0")
                //                            || !item.getPayCount().equals("0")
                //                            || !item.getReturnPayCount().equals("0")) {
                String mobile = Global.getMerchantMobileForMerchantNo(item.getMerchantNo());
                Intent bundle = new Intent(mContext, SimpleWebViewActivity.class);
                bundle.putExtra(SimpleWebViewActivity.WEBVIEW_URL, Api.depositH5Url +
                                                                           "?merchantNo=" + item.getMerchantNo() + "&mobile=" + mobile);
                bundle.putExtra(SimpleWebViewActivity.WEBVIEW_INIT_QBPAY, true);
                mContext.startActivity(bundle);
                //                } else {
                //                    Intent intent = new Intent(mContext, IntroducedServiceActivity.class);
                //                    mContext.startActivity(intent);
                //                }
            }
        });
    }

    @Override
    protected RecyclerView.ViewHolder onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        return new ShopViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_deposit_shop_list, parent, false));
    }

    @Override
    protected int getBaseItemViewType(int position) {
        return 0;
    }


    class ShopViewHolder extends RecyclerView.ViewHolder {
        TextView shopName;
        TextView shopAddr;
        TextView depositNum;

        public ShopViewHolder(View itemView) {
            super(itemView);
            shopName = itemView.findViewById(R.id.shop_name);
            shopAddr = itemView.findViewById(R.id.shop_addr);
            depositNum = itemView.findViewById(R.id.deposit_num);

        }
    }

}

